<html>
<head>
<title>
Chat Engine
</title>
<script type="text/javascript">
var user="amal";
var pass="pass";
var status=1;
var substatus=0;
var customstatus=0;
var statusmsg="";
var fc=1;
var ec=1;
var gc;
var lu;
var loggedin=0;
var working=0;
var timercount=0;
var gcctr=new Array();
var ctctr=new Array();
var friend=new Array();
var newmsg=new Array();
var min=new Array();
var chatter=new Array();
var conversation=new Array();
var conversationoptions=new Array();
var chatwindow=new Array();
var chatwindowwrapper=new Array();
var msgstatus=new Array();
var form1=new Array();
var chatinput=new Array();
var emot=new Array();
var emotprev=new Array();
var emotcurr=new Array();
var folded=new Array();

function login()
{
	if(loggedin==0)
	{
		fold("loginbox");
		for(var i=0;i<currstatus.length;i++)
		{
			if(substatus==0)
			{
				if(currstatus.options[i].value==status)
				{
				currstatus.selectedIndex=i;
				break;
				}
			}
			else
			{
				if(currstatus.options[i].value==substatus)
				{
				currstatus.selectedIndex=i;
				break;
				}
			}
		}
	}
	if(document.form3.username.value.length!="" && document.form3.password.value!="")
	{
		user=document.form3.username.value;
		pass=document.form3.password.value;
		startup();
		loggedin=1;
	}
}

function logout()
{
	user="";
	pass="";
	clearInterval(gc);
	clearInterval(lu);
	for(var i=0;i<=gcctr.length;i++)
	clearInterval(i);
	for(var i=0;i<=ctctr.length;i++)
	clearInterval(i);
	document.getElementById("chatlist").innerHTML="";
	loggedin=0;
	fold("loginbox");
}


function changestatus(k)
{
	if(k.substring(0,1)==0)
	{
	status=0;
	document.getElementById("curruser").innerHTML="<img class='status' src='offline.gif'>"+user;
	login();
	}
	else if(k.substring(0,1)==1)
	{
	status=1;
	document.getElementById("curruser").innerHTML="<img class='status' src='online.gif'>"+user;
	login();
	}
	else if(k.substring(0,1)==2)
	{
	status=2;
	document.getElementById("curruser").innerHTML="<img class='status' src='busy.gif'>"+user;
	login();
	}
	else if(k.substring(0,1)==3)
	{
	status=2;
	document.getElementById("curruser").innerHTML="<img class='status' src='away.gif'>"+user;
	login();
	}
	else if(k.substring(0,1)==4)
	{
	status=prompt("What is your status?","1");
	var tmp=document.createElement("option")
	statusmsg = prompt("What is ur msg to the world?","nothin much");
	tmp.text = statusmsg;
	for(var i=0;i<currstatus.length;i++)
	if(currstatus.options[i].value==status)
	var nextindex=i;
	currstatus.options.add(tmp,nextindex+1);
	customstatus++;
    tmp.value = status + "" + customstatus;
	substatus=tmp.value;
	currstatus.selectedIndex=tmp.index;
	changestatus(status);
	login();
	}
	else if(k.substring(0,1)==5)
	{
	loggedin=0;
	logout();
	document.getElementById("curruser").innerHTML="Please login.";
	}
	else
	{
		substatus=k;
	}
}

function startup()
{
	document.form3.username.value=user;
	document.form3.password.value=pass;
	loadusers();
	gc=setInterval("loadusers();",5000);
	lu=setInterval("getchat('');",1000);
	if(status==0)
	document.getElementById("curruser").innerHTML="<img class='status' src='offline.gif'>"+user;
	else if(status==1)
	document.getElementById("curruser").innerHTML="<img class='status' src='online.gif'>"+user;
	else if(status==2)
	document.getElementById("curruser").innerHTML="<img class='status' src='busy.gif'>"+user;
	else if(status==3)
	document.getElementById("curruser").innerHTML="<img class='status' src='away.gif'>"+user;
	
	var k=document.getElementsByTagName("div");
	for(var i=0;i<k.length;i++)
	{
		if(k[i].id.substring(k[i].id.length-9)=="container")
		{
			k[i].style.Height=window.innerHeight;
			k[i].style.Width=window.innerWidth;
		}
	}
}

function chat(frnd)
{
	if(frnd!="")
	{
		document.getElementById(frnd).style.color="#ffffff";
		document.getElementById(frnd).style.background="#606060";
		for(var i=1;i<=fc;i++)
		{
			if(friend[i]==frnd)
			break;
		}

		if(friend[i]!=frnd)
		{
			createnewchat(frnd);
		}
	}
	/*else
	{
		for(var j=1;j<=fc;j++)
		{
			if(friend[j]!="")
			{
			document.getElementById(friend[j]).style.color="#ffffff";
			document.getElementById(friend[j]).style.background="#606060";
			}
		}
	}*/
}

function createnewchat(frnd)
{
		if(frnd!="")
		{
			for(var tmpfc=1;tmpfc<=fc;)
			{
			if(friend[tmpfc]!="")
			tmpfc++;
			else
			break;
			}
			if(friend[tmpfc]!="")
			{
			tmpfc=fc;
			fc++;
			}
			
			friend[tmpfc]=frnd;
			min[tmpfc]=1;
			chatter[tmpfc]= document.createElement("div");
			chatter[tmpfc].id = "chatter"+tmpfc;
			chatter[tmpfc].className="chatter";
			chatter[tmpfc].style.left=(0.5+(tmpfc-1)*13).toString() + "%";
			document.body.appendChild(chatter[tmpfc]);
			
			conversation[tmpfc]= document.createElement("div");
			conversation[tmpfc].id = "conversation"+tmpfc;
			conversation[tmpfc].className="conversation";
			conversation[tmpfc].addEventListener("click",function () {minconversation(this.id.substring(12))},false);
			conversation[tmpfc].innerHTML=friend[tmpfc];
			chatter[tmpfc].appendChild(conversation[tmpfc]);
			
			conversationoptions[tmpfc]= document.createElement("div");
			conversationoptions[tmpfc].id = "conversationoptions"+tmpfc;
			conversationoptions[tmpfc].className="conversationoptions";
			conversationoptions[tmpfc].addEventListener("mouseover",function () {this.style.color='red'},false);
			conversationoptions[tmpfc].addEventListener("mouseout",function () {this.style.color='#808080'},false);
			conversationoptions[tmpfc].addEventListener("click",function () {closeconversation(this.id.substring(19))},false);
			conversationoptions[tmpfc].innerHTML="X";
			chatter[tmpfc].appendChild(conversationoptions[tmpfc]);	

			chatwindow[tmpfc]= document.createElement("div");
			chatwindow[tmpfc].id = "chatwindow"+tmpfc;
			chatwindow[tmpfc].className="chatwindow";
			chatwindow[tmpfc].innerHTML="";
			chatter[tmpfc].appendChild(chatwindow[tmpfc]);	
			
			msgstatus[tmpfc]= document.createElement("div");
			msgstatus[tmpfc].id = "msgstatus"+tmpfc;
			msgstatus[tmpfc].className="msgstatus";
			chatter[tmpfc].appendChild(msgstatus[tmpfc]);	
			if(document.getElementById(friend[tmpfc]).className[0]=="a")
			{
			msgstatus[tmpfc].innerHTML=friend[tmpfc] + " is online.";
			}
			else if(document.getElementById(friend[tmpfc]).className[0]=="b")
			{
			msgstatus[tmpfc].innerHTML=friend[tmpfc] + " is offline. Messages you send will be delivered when " + friend[tmpfc] + " comes online.";
			}
			else if(document.getElementById(friend[tmpfc]).className[0]=="c")
			{
			msgstatus[tmpfc].innerHTML=friend[tmpfc] + " is busy. You may be interrupting.";
			}
			
			form1[tmpfc]= document.createElement("form");
			form1[tmpfc].name = "form1"+tmpfc;
			chatter[tmpfc].appendChild(form1[tmpfc]);
			
			chatinput[tmpfc]= document.createElement("textarea");
			chatinput[tmpfc].id = "chatinput"+tmpfc;
			chatinput[tmpfc].name = "chatinput"+tmpfc;
			chatinput[tmpfc].rows = "1";
			chatinput[tmpfc].cols = "24";
			chatinput[tmpfc].addEventListener("keyup",function (e) {conversation[this.id.substring(9)].style.background="#ffffff";checkinput(e,this.id.substring(9))},false);
			chatinput[tmpfc].addEventListener("click",function () {conversation[this.id.substring(9)].style.background="#ffffff";},false);
			chatinput[tmpfc].className="chatinput";
			form1[tmpfc].appendChild(chatinput[tmpfc]);
			
			var tmp1=function (tmpfc){getchat(tmpfc);};
			gcctr[tmpfc]=setInterval(tmp1,500);
			var tmp2=function (tmpfc){checktyping(tmpfc);};
			ctctr[tmpfc]=setInterval(tmp2,1000);
		}
}

function showresult()
{
	if(document.form2.filter.value=="")
	loadusers();
	else
	{
		var arr = document.getElementsByTagName("div");
	
		for(var i=0; i<=arr.length;i++)
		{
			if(arr[i].className=="achatlist" || arr[i].className=="bchatlist" || arr[i].className=="cchatlist" || arr[i].className=="dchatlist" )
			{
				arr[i].style.display="none";
				if(arr[i].id.toLowerCase().match(document.form2.filter.value.toLowerCase()))
				{
					arr[i].style.display="block";
				}
			}
		}
	}
	chat("");
}

function loadusers()
{
	if(document.form2.filter.value=="")
	{
		if (window.XMLHttpRequest)
		{
			xmlhttp=new XMLHttpRequest();
		}
		else
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if(xmlhttp.responseText.substring(0,10)=="#userlist#")
				{
					document.getElementById("chatlist").innerHTML=xmlhttp.responseText.substring(10);
					chat("");
				}
			}
		}
		xmlhttp.open("GET","update.php?u="+user+"&p="+pass+"&s="+status+"&d="+statusmsg,true);
		xmlhttp.send();
	}
}

function sendchat(frnd)
{
	var tmpstatus=msgstatus[frnd].innerHTML;
	if (window.XMLHttpRequest)
	{
		xmlhttpsendchat=new XMLHttpRequest();
	}
	else
	{
		xmlhttpsendchat=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttpsendchat.onreadystatechange=function()
	{
 	 if (xmlhttpsendchat.readyState==4 && xmlhttpsendchat.status==200)
		{
			if(xmlhttpsendchat.responseText.substring(0,11)=="#chatadded#")
			{
				if(xmlhttpsendchat.responseText.substring(11)==friend[frnd])
				{
					msgstatus[frnd].innerHTML="Message sent to " + friend[frnd] + ".";
					setTimeout(function(){msgstatus[frnd].innerHTML=tmpstatus;},1500);
				}
			}
		}
	}
	xmlhttpsendchat.open("GET","update.php?u="+user+"&p="+pass+"&f="+friend[frnd]+"&t="+chatinput[frnd].value+"&h=0"+"&s="+status+"&d="+statusmsg,true);
	xmlhttpsendchat.send();
}

function typing(t)
{
	if (window.XMLHttpRequest)
	{
		xmlhttptyping=new XMLHttpRequest();
	}
	else
	{
		xmlhttptyping=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttptyping.onreadystatechange=function()
	{
 	 if (xmlhttptyping.readyState==4 && xmlhttptyping.status==200)
		{
			if(xmlhttptyping.responseText!="#"+user+"#typing")
			{
			//unable to connect to server
			}
		}
	}
	xmlhttptyping.open("GET","update.php?u="+user+"&p="+pass+"&w="+t+"&s="+status+"&d="+statusmsg,true);
	xmlhttptyping.send();
}

function checktyping(frnd)
{
	if (window.XMLHttpRequest)
	{
		xmlhttptyping=new XMLHttpRequest();
	}
	else
	{
		xmlhttptyping=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttptyping.onreadystatechange=function()
	{
 	 if (xmlhttptyping.readyState==4 && xmlhttptyping.status==200)
		{
			if(xmlhttptyping.responseText=="#"+friend[frnd]+"typing")
			{
				var prevstatus=msgstatus[frnd].innerHTML;
				msgstatus[frnd].innerHTML=friend[frnd] + " is typing...";
				setTimeout(msgstatus[frnd].innerHTML=prevstatus,1000);
			}
		}
	}
	xmlhttptyping.open("GET","update.php?u="+user+"&p="+pass+"&f="+friend[frnd]+"&w=2"+"&s="+status+"&d="+statusmsg,true);
	xmlhttptyping.send();
}

function isafriend(frnd)
{
	var exist;
	for(var j=1;j<=fc;j++)
	{
		if(friend[j]==frnd)
		{
			exist=1;
			break;
		}
	}
	
	if(exist==1)
	return j;
	else
	return false;
}

/*function getchat(frnd)
{
	if (window.XMLHttpRequest)
	{
		xmlhttpgetchat=new XMLHttpRequest();
	}
	else
	{
		xmlhttpgetchat=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttpgetchat.onreadystatechange=function()
	{
 	 if (xmlhttpgetchat.readyState==4 && xmlhttpgetchat.status==200)
		{
			if(xmlhttpgetchat.responseText.substring(0,5)=="#msg#")
			{
				//alert(xmlhttpgetchat.responseText.substring(xmlhttpgetchat.responseText.indexOf("#",5)+1));
				var tmpfriend=xmlhttpgetchat.responseText.substring(5,xmlhttpgetchat.responseText.indexOf("#",5));
				var tmpfrnd=isafriend(tmpfriend);
				if(tmpfrnd)
				{
					//alert(tmpfriend+" is a friend with id "+frnd);
					//if(chatwindow[frnd].innerHTML!="")
					//{
						chatwindow[tmpfrnd].innerHTML=chatwindow[tmpfrnd].innerHTML + "<b>" + tmpfriend+": </b>" + trimtext(xmlhttpgetchat.responseText.substring(xmlhttpgetchat.responseText.indexOf("#",5)+1),tmpfriend);
					//}
					//else
					//{
					//	chatwindow[frnd].innerHTML="<b>" + tmpfriend+": </b>" + trimtext(xmlhttpgetchat.responseText.substring(xmlhttpgetchat.responseText.indexOf("#",5)+1),tmpfriend);
					//}
				
					chatwindow[tmpfrnd].scrollTop=chatwindow[tmpfrnd].scrollHeight;
					document.getElementById("soundeffect").src="notify.wav";
				
					newmsg[timercount++]=setInterval(function aa()
					{
					conversation[tmpfrnd].style.background="orange";
					setTimeout(function a(){conversation[tmpfrnd].style.background="#ffffff";},500);
					},1000);
				}
				else
				{
				chat(tmpfriend);
				var tmpfrnd=isafriend(tmpfriend);
				//alert(tmpfriend+" is a new guy with id "+frnd);
				chatwindow[tmpfrnd].innerHTML="<b>" + tmpfriend+": </b>" + trimtext(xmlhttpgetchat.responseText.substring(xmlhttpgetchat.responseText.indexOf("#",5)+1),tmpfriend);
				chatwindow[tmpfrnd].scrollTop=chatwindow[tmpfrnd].scrollHeight;
				document.getElementById("soundeffect").src="notify.wav";
				newmsg[timercount++]=setInterval(function aa()
				{
					conversation[tmpfrnd].style.background="orange";
					setTimeout(function a(){conversation[tmpfrnd].style.background="#ffffff";},500);
				},1000);
				}
			}
		}
	}
	xmlhttpgetchat.open("GET","update.php?u="+user+"&p="+pass+"&f="+friend[frnd]+"&h=0",true);
	xmlhttpgetchat.send();
}*/

function getchat(frnd)
{
	if (window.XMLHttpRequest)
	{
		xmlhttpgetchat=new XMLHttpRequest();
	}
	else
	{
		xmlhttpgetchat=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttpgetchat.onreadystatechange=function()
	{
 	 if (xmlhttpgetchat.readyState==4 && xmlhttpgetchat.status==200)
		{
			if(xmlhttpgetchat.responseText.substring(0,5)=="#msg#")
			{
				var tmpfriend=xmlhttpgetchat.responseText.substring(5,xmlhttpgetchat.responseText.indexOf("#",5));
				chat(tmpfriend);
				var tmpfrnd=isafriend(tmpfriend);
				chatwindow[tmpfrnd].innerHTML=chatwindow[tmpfrnd].innerHTML + "<br><div class='plaintitle'><b>" + tmpfriend+": </b></div>" + trimtext(xmlhttpgetchat.responseText.substring(xmlhttpgetchat.responseText.indexOf("#",5)+1),tmpfriend);
				chatwindow[tmpfrnd].scrollTop=chatwindow[tmpfrnd].scrollHeight;
				document.getElementById("soundeffect").innerHTML='<embed src="notify.wav" height="0" width="0" autostart=true loop=false name="sound1" id="sound1"/>';
				//setTimeout(document.getElementById("soundeffect").innerHTML="",1000);
				//newmsg[timercount++]=setInterval(function aa()
				//{
				conversation[tmpfrnd].style.background="orange";
				//setTimeout(function a(){conversation[tmpfrnd].style.background="#ffffff";},500);
				//},1000);
			}
		}
	}
	
	if(frnd=="")
	xmlhttpgetchat.open("GET","update.php?u="+user+"&p="+pass+"&f=all"+"&h=0"+"&s="+status+"&d="+statusmsg,true);
	else
	xmlhttpgetchat.open("GET","update.php?u="+user+"&p="+pass+"&f="+friend[frnd]+"&h=0"+"&s="+status+"&d="+statusmsg,true);
	
	xmlhttpgetchat.send();
}

/*function cleartimers()
{
	for(var i=0;i<=timercount;i++)
	{
		clearInterval(newmsg[i]);
	}
}*/

function checkfilter(e)
{
	var keynum = 0;
	if(window.event)
	{
		keynum = e.keyCode;
	}
	else if(e.which)
	{
		keynum = e.which;
	}

	if(keynum==27 || keynum==13)
	{
		document.form2.filter.value="";
		return false;
	}
	else
	{
		showresult();
	}
}

function checkinput(e,frnd)
{
	var keynum = 0;
	if(e.which)
	
	{
		keynum = e.which;
	}

	if(keynum==13 && chatinput[frnd].value.substring(0,2)!="\n")
	{
		typing(1);
		if(chatwindow[frnd].innerHTML.length>0)
		chatwindow[frnd].innerHTML=chatwindow[frnd].innerHTML + "<br><div class='plaintitle'><b>" + user + ": </b></div>" + trimtext(chatinput[frnd].value,user);
		else
		chatwindow[frnd].innerHTML=chatwindow[frnd].innerHTML + "<div class='plaintitle'><b>" + user + ": </b></div>" + trimtext(chatinput[frnd].value,user);
		sendchat(frnd);
		chatinput[frnd].value="";
		chatwindow[frnd].scrollTop=chatwindow[frnd].scrollHeight;
		return false;
	}
	else if(keynum==13 && chatinput[frnd].value.substring(0,2)=="\n")
	{
		chatinput[frnd].value="";
		return false;
	}
	else
	{
		typing(0);
	}
}

function closeconversation(frnd)
{
	clearInterval(gcctr[frnd]);
	gcctr[frnd]="";
	clearInterval(ctctr[frnd]);
	ctctr[frnd]="";
	document.getElementById(friend[frnd]).style.color="#000000";
	document.getElementById(friend[frnd]).style.background="#ffffff";
	chatter[frnd].style.display="none";
	friend[frnd]="";
	
	for(var i=1;i<fc;i++)
	{
		if(i==1)
		chatter[i].style.left=(0.5).toString() + "%";
		else
		chatter[i].style.left=(0.5+(i-2)*13).toString() + "%";
	}
}

function minconversation(frnd)
{
	min[frnd]=min[frnd]*-1;
	if(min[frnd]==-1)
	{
		chatter[frnd].className="chattermin";
		chatwindow[frnd].style.visible="hidden";
		chatinput[frnd].style.display="none";
		chatwindow[frnd].className="chatwindowmin";
		chatinput[frnd].className="chatinputmin";
		msgstatus[frnd].style.display="none";
	}
	else
	{
		chatter[frnd].className="chatter";
		chatwindow[frnd].style.visible="visible";
		chatinput[frnd].style.display="block";
		chatwindow[frnd].className="chatwindow";
		chatinput[frnd].className="chatinput";
		msgstatus[frnd].style.display="block";
	}
}

function trimtext(tmp,extra)
{
	tmp=tmp.replace(/\</g,"<<text>");
	tmp=tmp.replace(/\&/g,"&<text>");
	return addemot("<span style='width: 100%;background-color: #ff0000;word-wrap: break-word;'>"+tmp+"</span>");
}

function emoticonhandler(type,j)
{
	var emotmax;
	clearInterval(emotprev[j]);
	emot[j]=0;
	
	if(type=="01" || type=="02" || type=="04" || type=="05" || type=="06" || type=="07" || type=="08" || type=="09" || type=="10" || type=="12")
	emotmax=1230;
	else if(type=="03")
	emotmax=570;
	else if(type=="11")
	emotmax=820;
		
	emotprev[j]=setInterval(function(){if(emot[j]<emotmax){
	var i="-" + emot[j].toString() + "px";
	document.getElementById("emot"+type.toString()+j.toString()).style.top=i;
	emot[j]=emot[j]+14;
	}
	},85);
}

function addemot(k)
{
	var emoted=k;
	var tmptmpec=ec;
	var emot01=emoted.match(/(\:\)|\:\-\))/g);
	var emot02=emoted.match(/\:D/g);
	var emot03=emoted.match(/(\;\)|\;\-\))/g);
	var emot04=emoted.match(/\:\'\(/g);
	var emot05=emoted.match(/\:\-o/gi);
	var emot06=emoted.match(/\:\-\//g);
	var emot07=emoted.match(/x\-\(/gi);
	var emot08=emoted.match(/\:\(/g);
	var emot09=emoted.match(/B\-\)/g);
	var emot10=emoted.match(/\:P/gi);
	var emot11=emoted.match(/\<3/g);
	var emot12=emoted.match(/\:\-\|/g);
		
	if(emot01)
	{
		var type="01";
		var tmpec=ec;
		for(var i=ec;i<ec+emot01.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/(\:\)|\:\-\))/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot02)
	{
		var type="02";
		var tmpec=ec;
		for(var i=ec;i<ec+emot02.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\:D/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot03)
	{
		var type="03";
		var tmpec=ec;
		for(var i=ec;i<ec+emot03.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/(\;\)|\;\-\))/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot04)
	{
		var type="04";
		var tmpec=ec;
		for(var i=ec;i<ec+emot04.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\:\'\(/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot05)
	{
		var type="05";
		var tmpec=ec;
		for(var i=ec;i<ec+emot05.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\:\-o/i,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot06)
	{
		var type="06";
		var tmpec=ec;
		for(var i=ec;i<ec+emot06.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\:\-\//,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot07)
	{
		var type="07";
		var tmpec=ec;
		for(var i=ec;i<ec+emot07.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/x\-\(/i,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot08)
	{
		var type="08";
		var tmpec=ec;
		for(var i=ec;i<ec+emot08.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\:\(/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot09)
	{
		var type="09";
		var tmpec=ec;
		for(var i=ec;i<ec+emot09.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/B\-\)/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot10)
	{
		var type="10";
		var tmpec=ec;
		for(var i=ec;i<ec+emot10.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\:P/i,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot11)
	{
		var type="11";
		var tmpec=ec;
		for(var i=ec;i<ec+emot11.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\<3/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	if(emot12)
	{
		var type="12";
		var tmpec=ec;
		for(var i=ec;i<ec+emot12.length;i++)
		{
		var data="</div><div id='emotcont" + type + tmpec.toString() + "' class='emoticoncontainer'>"
		data+="<img id='emot" + type + tmpec.toString() + "' class='emoticon' src='emot" + type + ".png'";
		data+=" onmouseover='emoticonhandler(this.id.substring(4,6),this.id.substring(6));'/></div><div class='plaintext'>";
		emoted=emoted.replace(/\:\-\|/,data);
		emotcurr[i]=type + tmpec;
		tmpec++;
		}
		ec=tmpec;
	}
	
	for(var i=tmptmpec;i<ec;i++)
	{
	emoticonhandler(emotcurr[i].substring(0,2),emotcurr[i].substring(2));
	}
	return emoted;
}

function fold(k)
{
	if(working!=1)
	{
		working=1;
		if(document.getElementById(k+"foldcontent").className=="foldable")
		{
			var obj=document.getElementById(k+"foldcontent");
			var j=1.0;
			var step=obj.offsetHeight/10;
			folded[k]=step;
			var ten=0;
			var foldtimer=setInterval(function(){if(ten<10){obj.style.height=obj.offsetHeight-step;obj.style.MozOpacity=j;j=j-0.1;ten++;}else{obj.style.display="none";working=0;clearInterval(foldtimer);}},50);
			document.getElementById(k+"foldcontent").className="unfoldable";
			if(document.getElementById(k+"foldtitle"))
			document.getElementById(k+"foldtitle").innerHTML="-";
		}
		else if(document.getElementById(k+"foldcontent").className=="unfoldable")
		{
			var obj=document.getElementById(k+"foldcontent");
			obj.style.display="block";
			var j=0.0;
			var step=folded[k];
			var ten=0;
			var foldtimer=setInterval(function(){if(ten<10){obj.style.height=obj.offsetHeight+step;obj.style.MozOpacity=j;j=j+0.1;ten++;}else{obj.style.MozOpacity=1;obj.style.height=10*folded[k];working=0;clearInterval(foldtimer);}},50);
			document.getElementById(k+"foldcontent").className="foldable";
			if(document.getElementById(k+"foldtitle"))
			document.getElementById(k+"foldtitle").innerHTML="+";
		}
	}
}
</script>

<style type="text/css">
textarea.filter
{
	border: none;
	BORDER-RIGHT: #606060 1px solid;
	BORDER-TOP: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	//POSITION: absolute;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	width: 168px;
	height: 24px;
	padding-left:4px;
	padding-top:3px;
}
input.filter
{
	border: none;
	BORDER-RIGHT: #606060 1px solid;
	BORDER-TOP: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	//POSITION: absolute;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	width: 168px;
	height: 24px;
	//padding-left:4px;
	padding-bottom:3px;
}
select.filter
{
	border: none;
	BORDER-RIGHT: #606060 1px solid;
	BORDER-TOP: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	//POSITION: absolute;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	width: 168px;
	height: 24px;
	///padding-left:4px;
	//padding-top:2px;
}
DIV.chatlistholder
{
	//top: 20%;
	//POSITION: absolute;
	BORDER-TOP: #606060 1px solid;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	overflow:auto;
	width: 168px;
	height: 243px;
}
DIV.achatlist
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	padding-bottom: 2%;
	COLOR: #000000;
	cursor:pointer;
}
DIV.bchatlist
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	padding-bottom: 2%;
	COLOR: #000000;
	cursor:pointer;
}
DIV.cchatlist
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	padding-bottom: 2%;
	COLOR: #000000;
	cursor:pointer;
}
DIV.dchatlist
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	padding-bottom: 2%;
	COLOR: #000000;
	cursor:pointer;
}
DIV.achatlistselected
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	COLOR: #ffffff;
	font-size: 10pt;
	padding-bottom: 2%;
	background: #606060;
	cursor:pointer;
}
DIV.bchatlistselected
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	COLOR: #ffffff;
	font-size: 10pt;
	padding-bottom: 2%;
	background: #606060;
	cursor:pointer;
}
DIV.cchatlistselected
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	COLOR: #ffffff;
	font-size: 10pt;
	padding-bottom: 2%;
	background: #606060;
	cursor:pointer;
}
DIV.dchatlistselected
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	FONT-FAMILY: Arial;
	COLOR: #ffffff;
	font-size: 10pt;
	padding-bottom: 2%;
	background: #606060;
	cursor:pointer;
}
IMG.status
{
	//align:top;
	padding-top: 3%;
	padding-left:  2%;
	padding-right:  2%;
}
DIV.chatter
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	BORDER-TOP: #606060 1px solid;
	bottom:0%;
	width: 12.1%;
	//height:37%;
	position:absolute;
	//overflow:hidden;
	//COLOR: #000000;
}
DIV.chattermin
{
	BORDER-RIGHT: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	BORDER-TOP: #606060 1px solid;
	left: 19.5%;
	bottom:2%;
	width: 12.1%;
	height:2.5%;
	position:absolute;
	//overflow:hidden;
	//COLOR: #000000;
}
DIV.conversation
{
	FONT-FAMILY: Arial;
	COLOR: #808080;
	font-size: 10pt;
	padding-top:3px;
	padding-bottom:3px;
	padding-LEFT: 1.5%;
	//width: 20%;
	POSITION: relative;
	font-weight: bold;
	cursor:pointer;
}
DIV.conversationoptions
{
	FONT-FAMILY: Arial;
	COLOR: #808080;
	font-size: 10pt;
	padding-top:3px;
	padding-bottom:3px;
	top:0%;
	LEFT: 94.5%;
	//width: 20%;
	POSITION: absolute;
	z-index:1 ;
	font-weight: bold;	
	cursor:pointer;
}
DIV.chatwindow
{
	border: none;
	BORDER-TOP: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
	//BORDER-RIGHT: #606060 1px solid;
	//BORDER-LEFT: #606060 1px solid;
	POSITION: relative;
	//FLOAT: none;
	FONT-FAMILY: Arial;
	font-size: 11pt;
	height:200px;
	padding-left:5px;
	padding-top:3px;
	//overflow-x:hidden;
	overflow-y:auto;
	word-wrap: break-word;
}
DIV.chatwindowmin
{
	border: none;
	POSITION: relative;
	//width: 98%;
	height:0px;
	display:none;
}
textarea.chatinput
{
	border: none;
	BORDER-RIGHT: #606060 1px solid;
	BORDER-TOP: #606060 1px solid;
	BORDER-LEFT: #606060 1px solid;
	BORDER-BOTTOM: #606060 1px solid;
    FLOAT: none;
	POSITION: relative;
    TOP: 4px;
	left: 1.5%;
	width:97%;
	FONT-FAMILY: Arial;
	font-size: 11pt;
	padding-left:2px;
	padding-top:1px;
	//height: 12%;
}
textarea.chatinputmin
{
	border: none;
	POSITION: relative;
	left: 1.5%;
	width:97%;
	height:0%;
	FONT-FAMILY: Arial;
	font-size: 11pt;
}
DIV.msgstatus
{
	FONT-FAMILY: Arial;
	//BORDER-TOP: #606060 1px solid;
	//BORDER-BOTTOM: #606060 1px solid;
	COLOR: #808080;
	font-size: 8pt;
	padding-left: 1%;
	padding-right: 1%;
	text-align:center;
	POSITION: relative;
	padding-top: 2px;
	//padding-top: 6px;
	//padding-bottom: 6px;
	//bottom:0%;
}
div.emoticoncontainer
{
	float: left;
	overflow: hidden;
	height: 14px;
	width: 14px;
	padding-left: 2px;
	padding-right: 2px;
}
img.emoticon
{
	POSITION: relative;
}
div.plaintext
{
	float: left;
}
div.plaintitle
{
	//float: left;
}
DIV.curruser
{
	BORDER-TOP: #606060 1px solid;
	BORDER-left: #606060 1px solid;
	BORDER-right: #606060 1px solid;
	FONT-FAMILY: Arial;
	font-size: 10pt;
	overflow:auto;
	width: 8.7%;
	padding-bottom: 2px;
}
</style>
</head>

<body onLoad="startup();">
<div id="soundeffect"></div>

<form name="form3" action="return false;">
<div id="loginboxfoldtitle" onClick="fold(this.id.substring(0,this.id.length-9))">+</div>
<div id="loginboxfoldcontent" class="foldable">
<textarea class="filter" id="username" cols="13" value=""></textarea><br>
<textarea class="filter" id="password" cols="13" value=""></textarea><br>
<input name="Login" type="submit" class="filter" value="Login" onClick="login();return false;"><br><br>
</div>
<div id="curruser" class="curruser"></div>
<select class="filter" name="currstatus" id="currstatus" onChange="changestatus(this.value);">
  <option value="1">Available</option>
  <option value="2">Busy</option>
  <option value="3">Away</option>
  <option value="0">Invisible</option>
  <option value="4">Custom message</option>
  <option value="5">Sign out of chat</option>
</select>
</form>

<form name="form2">
<div id="chatlistfoldtitle" onClick="fold(this.id.substring(0,this.id.length-9))">+</div>
<div id="chatlistfoldcontent" class="foldable">
<textarea class="filter" id="filter" cols="13" onKeyUp="return checkfilter(event);" value=""></textarea>
<div class="chatlistholder" id="chatlist"></div>
</div>
</form>
hefdfdsfdsfhefdfdsfdsfd<br>
<<text>div>a<<text>/div></text>
llohefdfdsfdsfdllohefdfdsfdsfdllohefdfdsfd<br>
sfdll<br>
ohefdfdsfdsfdl<br><br>
lohefdfdsfdsfdllohe<br>
fdfdsfdsf<br>
dllohefdfdsfdsfdllollo<br>
</body>
</html>